//
//  YZFriendAddCell.m
//  VET
//
//  Created by lixiaoyi on 2018/7/13.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZFriendAddCell.h"
#import "ChatHeader.h"
@implementation YZFriendAddCell

- (void)layouViews{
//    [self.friendStateBtn setTitle:@"加好友" forState:UIControlStateNormal];
    UIView *superView = self.contentView;
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(superView.mas_left).with.offset(10);
        make.top.mas_equalTo(superView.mas_top).with.offset(12);
        make.right.mas_equalTo(self.nameLabel.mas_left).with.offset(-10);
        make.bottom.mas_equalTo(superView.mas_bottom).with.offset(-8);
        make.width.height.mas_equalTo(30);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImageView.mas_right).with.offset(10);
        make.top.mas_equalTo(superView.mas_top).with.offset(12);
        make.bottom.mas_equalTo(self.infoLabel.mas_top).with.offset(-8);
        make.right.mas_equalTo(self.friendStateBtn.mas_left).with.offset(-10);
    }];
    
    [self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLabel.mas_left);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).with.offset(8);
        make.bottom.mas_equalTo(superView.mas_bottom).with.offset(-5);
        make.right.mas_equalTo(self.nameLabel.mas_right);
    }];
    
    [self.friendStateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.ignoreBtn.mas_right).with.offset(10);
        make.right.mas_equalTo(superView.mas_right).with.offset(-10);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(30);
        make.centerY.mas_equalTo(superView);
    }];
}

- (void)setModel:(YZFriendModel *)model {
    super.model = model;
    NSString *icon = model.iconName;
    [self.iconImageView setImage:[UIImage imageNamed:icon]];
    [self.nameLabel setText:model.name];
    [self.infoLabel setText:model.info];
    
    if (model.friendState == NewFriendStateAdd) {
        [self.friendStateBtn setHidden:NO];
        [self.ignoreBtn setHidden:YES];
    }
    
    [self refreshFriendState];
}

- (void)refreshFriendState {
    if (super.model.friendState == NewFriendStateAdd) {
        // 加好友
        [self.friendStateBtn setTitle:@"加好友" forState:UIControlStateNormal];
        [self.friendStateBtn setTitleColor:XZRGB(0x32BE60) forState:UIControlStateNormal];
        [self.friendStateBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
        self.friendStateBtn.layer.cornerRadius = 10.0f;
        self.friendStateBtn.layer.masksToBounds = YES;
        self.friendStateBtn.layer.borderColor = XZRGB(0x32BE60).CGColor;
        self.friendStateBtn.layer.borderWidth = 1.0f;
        
        [self.friendStateBtn addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
}

#pragma mark - event
- (void)addBtnClick:(UIButton *)sender{
    if (self.addFriendBlock) {
        self.addFriendBlock();
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
